package cn.fl.project.service.impl;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.project.dto.PrjPrdPaySchBankDTO;
import cn.fl.project.service.IPrjPrdPaySchBankService;
import cn.fl.project.service.IPrjPrdPaySchMApiService;
import cn.fl.project.transform.PrjPrdPaySchBankVOTransform;
import cn.fl.project.vo.PrjPrdPaySchBankVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Description: 支付表结清账号记录表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class PrjPrdPaySchBankServiceImpl implements IPrjPrdPaySchBankService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(IPrjPrdPaySchBankService.class);
	
	@Autowired
	private IPrjPrdPaySchMApiService prjPrdPaySchMApiService;

	@Override
	public PrjPrdPaySchBankDTO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		//PrjPrdPaySchBankDTO dto = null;//this.自定义ApiService.selectById(id);
		return prjPrdPaySchMApiService.selectPrjPrdPaySchBankById(id);
	}

	@Override
	public Long add(PrjPrdPaySchBankVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		//return this.prjPrdPaySchBankApiService.add(PrjPrdPaySchBankVOTransform.toDTO(entity));
		return null;
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.prjPrdPaySchBankApiService.removeById(id);
		return false;
	}

	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return this.prjPrdPaySchMApiService.removePrjPrdPaySchBankByIds(ids);
    }

	@Override
	public boolean modify(PrjPrdPaySchBankVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.prjPrdPaySchBankApiService.modify(PrjPrdPaySchBankVOTransform.toDTO(entity));
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		page = this.prjPrdPaySchMApiService.searchPrjPrdPaySchBankListPage(page);
		List<PrjPrdPaySchBankDTO> DTOList = (List<PrjPrdPaySchBankDTO>) page.getResultList();
		List<PrjPrdPaySchBankVO> VOList = PrjPrdPaySchBankVOTransform.toVOList(DTOList);
		if(CollectionUtils.isNotEmpty(VOList)){
			for (PrjPrdPaySchBankVO prjPrdPaySchBankVO : VOList) {
				if(null!=prjPrdPaySchBankVO && null!=prjPrdPaySchBankVO.getPayAmt()){
					prjPrdPaySchBankVO.setPayAmtDouble(DecimalUtils.convertFenToYuan(prjPrdPaySchBankVO.getPayAmt()));//金额 分转元
				}
			}
		}

		page.setResultList(VOList);
		return page;
	}

	@Override
	public boolean batchAdd(List<PrjPrdPaySchBankVO> VOList) throws BaseException {
		if(CollectionUtils.isEmpty(VOList)){
			BaseLogUtils.info(logger, "batchAdd", "批量信息集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		/*if(CollectionUtils.isNotEmpty(prjBindComMoneyVoList)){
            prjPrdPaySchMApiService.batchAddPrjBindComMoney(PrjBindComMoneyVOTransform.toDTOList(prjBindComMoneyVoList));
        }*/
		return this.prjPrdPaySchMApiService.batchAddPrjPrdPaySchBank(PrjPrdPaySchBankVOTransform.toDTOList(VOList));
	}

	@Override
	public boolean modifyConfirmMark(Long paySchId, String fundFlowCd, String fundTypCd) throws BaseException {
		PrjPrdPaySchBankDTO dto = new PrjPrdPaySchBankDTO();
		dto.setPaySchId(paySchId);
		dto.setFundFlowCd(fundFlowCd);
		dto.setFundTypCd(fundTypCd);
		dto.setMdfTm(new Date());
		dto.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		return prjPrdPaySchMApiService.modifyConfirmMark(dto);
	}
}
